-- 格式要UTF8-BOM
local TWaryLua = require "TWaryLua";
local initData = require "1";
local json = require "json"; 
require "StringEx"



local content_all_info = "local all_info = {\n"





-- 打开配置文件
local file = io.open("./json/cn-hongkong.json", "r");
local content = file:read("*all");
file:close();
local instance = json.decode(content).Instance





for k,v in pairs(instance) do
    content_all_info = content_all_info .. "\n"
    print("------------------------------------")
    print("实例名称:", v.InstanceName)
    print("公网IP地址:", v.PublicIpAddress.IpAddress[1])
    print("内网IP地址:", v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress)
    print("内网MAC地址:", v.NetworkInterfaces.NetworkInterface[1].MacAddress)
    local mac = v.NetworkInterfaces.NetworkInterface[1].MacAddress:replaceAll(":","");

    -- 游戏服
    if v.InstanceName:startsWith("game-") then
        content_all_info = content_all_info .. '    game_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- game服务器地址(公) , \n'
        content_all_info = content_all_info .. '    game_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- game服务器地址(私) , \n'
        local game_server_guid = TWaryLua.MD5(mac:upper());
        content_all_info = content_all_info .. '    game_server_guid = "' .. game_server_guid .. '",-- -- 游戏服机器标识, \n'    
        print("游戏服机器标识:", game_server_guid)        
    elseif v.InstanceName:startsWith("web-") then
        content_all_info = content_all_info .. '    web_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- web服务器地址(公) , \n'
        content_all_info = content_all_info .. '    web_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- web服务器地址(私) , \n'
    elseif v.InstanceName:startsWith("java-") then
        content_all_info = content_all_info .. '    java_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- java服务器地址(公) , \n'
        content_all_info = content_all_info .. '    java_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- java服务器地址(私) , \n'
    elseif v.InstanceName:startsWith("javam-") then
        content_all_info = content_all_info .. '    javam_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- javam服务器地址(公) , \n'
        content_all_info = content_all_info .. '    javam_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- javam服务器地址(私) , \n'
    elseif v.InstanceName:startsWith("sql-") then        
        content_all_info = content_all_info .. '    sql_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- sql服务器地址(公) , \n'
        content_all_info = content_all_info .. '    sql_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- sql服务器地址(私) , \n'
    else
        print("未知的实例, 名称是", v.InstanceName)
    end;

    content_all_info = content_all_info .. "\n"
end;




-- 打开配置文件
local file = io.open("./json/cn-shenzhen.json", "r");
local content = file:read("*all");
file:close();
local instance = json.decode(content).Instance





for k,v in pairs(instance) do
    content_all_info = content_all_info .. "\n"
    print("------------------------------------")
    print("实例名称:", v.InstanceName)
    print("公网IP地址:", v.PublicIpAddress.IpAddress[1])
    print("内网IP地址:", v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress)
    print("内网MAC地址:", v.NetworkInterfaces.NetworkInterface[1].MacAddress)

     -- proxy服
    if v.InstanceName:startsWith("proxy-") then
        content_all_info = content_all_info .. '    proxy_address_public = "' .. v.PublicIpAddress.IpAddress[1] .. '",-- proxy服务器地址(公) , \n'
        content_all_info = content_all_info .. '    proxy_address_private = "' .. v.NetworkInterfaces.NetworkInterface[1].PrimaryIpAddress .. '",-- proxy服务器地址(私) , \n'
    end;
    content_all_info = content_all_info .. "\n"
end;


content_all_info = content_all_info .. [[
}

return all_info;
]]

TWaryLua.SaveToFile("./lua/all_info.lua", content_all_info)
print(content_all_info)
print("正在保存 lua 配置文件 ./lua/all_info.lua")

